package com.dragon.sso.service;

import com.dragon.sso.dto.CustomUserDetail;
import java.util.HashMap;
import javax.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author bin.wei
 */
@Component
@Slf4j
public class CustomUserDetailService implements UserDetailsService {

  private HashMap<String, UserDetails> inMemoryUsers;

  @PostConstruct
  private void init() {
    inMemoryUsers = new HashMap<>();
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    inMemoryUsers.put("admin", new CustomUserDetail("admin", passwordEncoder.encode("123456"),"管理员", "17779626819", "admin"));
  }

  @Override
  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    return inMemoryUsers.get(username);
  }
}



